﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using DevExpress.Web.ASPxMenu;
using SGRapidForm.Common;
using SGRapidForm.Permission.Service.Interface;
using SGRapidForm.Permission.Entity;
using DevExpress.Web.ASPxClasses;

namespace SGDemo.Permission
{
    public partial class RoleItem : System.Web.UI.Page
    {
        private IPermissionService _permissionService = ServiceProxyFactory.Create<IPermissionService>("permissionservice");

        protected void Page_Load(object sender, EventArgs e)
        {
            JSManager.RegAjax(Header, this.GetType().BaseType);
        }
        /// <summary>
        /// 部门的回调函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void module_OnCallback(object sender, CallbackEventArgsBase e)
        {
            string userkeyid = e.Parameter;
            lbmodule.DataSource = _permissionService.Module_GetByRokeKeyid(userkeyid);
            lbmodule.DataBind();
        }
        /// <summary>
        /// 新增保存
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod] 
        public bool SaveForAdd(Role user)
        {
            //加入Session等服务端信息
            user.CreateName = "Creater";
            user.CreateDate = System.DateTime.Now;
            return _permissionService.Role_Add(user);
        }

        /// <summary>
        /// 获取一位用户明细
        /// </summary>
        /// <param name="keyid">用户Keyid</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public Role GetRoleByKeyid(string keyid)
        {
            return _permissionService.Role_GetByKeyid(keyid);
        }

        /// <summary>
        /// 编辑保存
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public bool SaveForEdit(Role user)
        {
            //加入Session等服务端信息
            user.ModifyName = "Editer";
            user.ModifyDate = System.DateTime.Now;
            bool ret = _permissionService.Role_Update(user);
            return ret;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="keyid">用户Keyid</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public bool Delete(string keyid)
        {
            return _permissionService.Role_Delete(keyid);
        }
    }
}